﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HCFramework.API.LINQ;

namespace C
{
    public class VisitorLogController
    {
        public static void Insert()
        {
            VisitorLog v = new VisitorLog();
            Insert(v);
        }

        public static void Insert(VisitorLog a)
        {
            HCDataContext db = new HCDataContext();
            a.Date = DateTime.Now;
            a.IpAddress = M.Common.GetIpAddress();
            a.Username = C.UserController.GetUsername();
            db.VisitorLogs.InsertOnSubmit(a);
            db.SubmitChanges();
        }

        public static void Update(VisitorLog a, HCDataContext db)
        {
            db.SubmitChanges();
        }

        public static void Delete(int id)
        {
            HCDataContext db = new HCDataContext();
            VisitorLog a = db.VisitorLogs.Where(
                ik => ik.VisitorLogID == id).First();
            db.VisitorLogs.DeleteOnSubmit(a);
            db.SubmitChanges();
        }

        public static VisitorLog GetByID(int id, HCDataContext db)
        {
            return db.VisitorLogs.Where(
                ik => ik.VisitorLogID == id).FirstOrDefault();
        }

        public static VisitorLog GetByID(int id)
        {
            return GetByID(id, new HCDataContext());
        }
    }
}